<?php

namespace app\push\model;

require_once ROOT_PATH.'vendor\GatewayWorker\GateWay.php';
use GatewayClient\Gateway as work;
use Exception;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/2
 * Time: 23:20
 */
class PushMessage
{
    //向所有客户端连接广播消息
    public function sendToAll($message)
    {
        work::sendToAll($message);
        jsonArray(200, '广播成功');
    }
    /**
     *
     * 用户加入聊天组
     * @param       array      $user
     * @param       string     $clientId
     * */
    public function joinGroup($user_id, $clientId)
    {
        try{
            if(work::isOnline($clientId))
            {
                //绑定用户id bindUid($client_id, $uid)
                work::bindUid($clientId, $user_id);
                //绑定推送组  nice模拟一个组名
                work::joinGroup($clientId,"nice");
                jsonArray(200, '连接成功');
            }else
            {
                jsonArray(401, '没有登录');
            }

        }catch(Exception $e){
            jsonArray(401, '连接失败'.$e->getMessage());
        }

    }


}